package com.group9.handinhand.dao.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.apache.commons.lang.ArrayUtils;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.group9.handinhand.service.so.PasswordResetLinkSO;

@Entity
@Table(name = "PASSWORD_RESET_LINK")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class PasswordResetLink extends AbstractBaseModel {

	private static final long serialVersionUID = 1L;
	
	@Column(name = "LINK", nullable = false, unique = true, length = 30, updatable = false)
	private String link;
	
	@ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "USER_ID", nullable = false, updatable = false)
    private User user;

	public PasswordResetLinkSO convertToServiceObject(String... ignoreProperties) {
		PasswordResetLinkSO so = (PasswordResetLinkSO) convert(new PasswordResetLinkSO(), 
			(String[]) ArrayUtils.addAll(ignoreProperties, new String[]{"user"}));
		so.setUser(user.convertToServiceObject(new String[]{"socialUsers"}));
		return so;
	}
	
	public String getLink() {
		return link;
	}

	public void setLink(String link) {
		this.link = link;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Override
	public String toString() {
		return "PasswordResetLink [link=" + link + ", user=" + user + "]";
	}

}
